#include <cstdio>
#include <cstring>
 
int reserveData(char a[])
{
    int len = strlen(a);
    for ( int i = 0; i < len/2; i++ ) {
        char t = a[i];
        a[i] = a[len-i-1];
        a[len-i-1] = t;
    }
    return len;
}
 
void ch2Data(char a[], int len)
{
    for ( int i = 0; i < len; i++ )
    {
    	if ( a[i] >= '0' && a[i] <= '9' ) {
    		a[i] = a[i] - '0';	
    	}
    	else {
    		a[i] = a[i] - 'A' + 10;
    	}
    }
}
 
int addData(char a[], int lena, char b[], int lenb, int m)
{
    int max = lena;
    if ( max < lenb ) {
        max = lenb;
    }
    int k = 0;
    for ( int i = 0; i < max; i++ ) {
        int x = a[i] + b[i] + k;
        a[i] = x % m;
        k = x / m; 
    }
    if ( k > 0 ) {
        a[max] = k;
        max ++;
    }
    return max;
}
 
int main()
{
	freopen("sum10.in",  "r", stdin);
	freopen("sum10.ans", "w", stdout);
    char a[10001] = {0};
    char b[10001] = {0};
    int  m = 0;
    scanf("%d", &m);
    scanf("%s %s", a, b);
    int lena = reserveData(a);
    int lenb = reserveData(b);
    ch2Data(a, lena);
    ch2Data(b, lenb);
    int len = addData(a, lena, b, lenb, m);
    for ( int i = len-1; i>=0; i-- ) {
    	if ( a[i] < 10 ) {
    		printf("%d", a[i]);	
    	}
    	else {
    		printf("%c", a[i] - 10 + 'A');
    	}
    }
    return 0;
}
